const Socket = require("socket.io")

module.exports.socket = (server,frameSyncExecutor) => {
  // 跨域处理
  const io = Socket(server, { origin: "*:*", cors: true })

  // 主程序
  // 连接
  io.on('connection', socket => {
    console.log('有人偷偷连上了哦');
    socket.on('join', msg=>{
      frameSyncExecutor.addConnectionInpFrame(socket,msg,io)
    })
    socket.on('leave',msg=>{
      frameSyncExecutor.leaveConnectionInpFrame(socket)
    })
    socket.on('update1', msg => {
      frameSyncExecutor.syncStateData(msg,socket)
    })
  })
  // 断开
  io.on('disconnect', () => { })

  return io
}